package org.genitus.druidry

import in.zapr.druid.druidry.Interval
import in.zapr.druid.druidry.aggregator.DruidAggregator
import in.zapr.druid.druidry.filter.DruidFilter
import in.zapr.druid.druidry.granularity.Granularity
import in.zapr.druid.druidry.postAggregator.DruidPostAggregator
import org.joda.time.DateTime

class DruidTimeseriesResponse[T<:DruidTimeseriesResult] {
  var timestamp:String =_
  var result:T = _

  def this(timestamp:String,result:T) {
    this()
    this.timestamp = timestamp
    this.result = result
  }

  def this(timestamp:DateTime) = {
    this()
    this.timestamp = timestamp.toString()
  }

  def convertResult(clazz: Class[T]):T = {
    if (this.result == null)
      result = clazz.newInstance()
    result.timestamp = new DateTime(this.timestamp).getMillis
    result
  }
}

abstract class DruidTimeseriesResult {
  var timestamp:Long = _
}

abstract class DruidTimeseriesSearch {
  def druidDataSource:String
  def druidIntervals:List[Interval]
  def druidGranularity: Granularity

  def druidFilter: Option[DruidFilter] = None
  def druidAggregators: Option[List[DruidAggregator]] = None
  def druidEmptyFilling: Boolean = false
  def druidPostAggregators: Option[List[DruidPostAggregator]] = None
}